package com.bms.controller;

import com.alibaba.fastjson.JSON;
import com.bms.Dao.BookDao;
import com.bms.bean.Book;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class GetBook {

    @Autowired
    BookDao bookDao;

    //    热门图书推荐
    @RequestMapping("/HotBook")
    public String getHotBook() {
        Book[] books = bookDao.getBookByHot();
        String res = JSON.toJSONString(books);
        return res;
    }

    //新书推荐
    @RequestMapping("/NewBook")
    public String getNewBook() {
        Book[] books = bookDao.getBookByOnTime();
        String res;
        res = JSON.toJSONString(books);
        return res;
    }

    //通过作者查询
    @RequestMapping("/ByBookAuthor")
    public String getBookByAuthor(@RequestBody Book book) {
        String name="%"+book.getBookauthor()+"%";
        System.out.println(name);
        Book[] books = bookDao.getBookByAuthor(name);
        return JSON.toJSONString(books);
    }

    //通过书名查询
    @RequestMapping("/ByBookName")
    public String getBookByName(@RequestBody Book book) {
        String name="%"+book.getBookname()+"%";
        Book[] books = bookDao.getBookByName(name);
        return  JSON.toJSONString(books);
    }

    //通过书号查询
    @RequestMapping("/ByBookNumber")
    public String getBookByNumber(@RequestBody Book book)
    {
        String number = book.getBooknumber();
        Book[] books = bookDao.getBookByNumber(number);
        return  JSON.toJSONString(books);
    }


}
